package com.gtxc.kotlinmvvm.network

import android.os.Bundle
import android.os.IBinder
import android.view.*
import android.widget.EditText
import androidx.databinding.ViewDataBinding
import com.aleyn.mvvm.base.BaseActivity
import com.aleyn.mvvm.base.BaseViewModel
import com.aleyn.mvvm.base.BaseViewModel.Companion.TITLE_BAR_BACK
import com.aleyn.mvvm.event.Message


/**
 * Created by houzhanlei
 * 2020/7/22
 * 为自己代码负责
 */
abstract class CommonBaseActivity<VM : BaseViewModel, DB : ViewDataBinding> : BaseActivity<VM, DB>() {

    override fun onCreate(savedInstanceState: Bundle?) {
      //  requestWindowFeature(Window.FEATURE_NO_TITLE)
        super.onCreate(savedInstanceState)
    }

    override fun initView(savedInstanceState: Bundle?) {
        //沉浸状态栏 和深色文本

    }

    //


    override fun handleEvent(msg: Message) {
        //如果是titleBar back 关掉act else 分发event
        if (msg.code == TITLE_BAR_BACK) {
            finishAct()
        } else {
            super.handleEvent(msg)
        }

    }


    /**
     * 结束关闭act
     * @param
     */
    protected open fun finishAct() {
    }

    /**
     * 结束关闭act
     * @param
     */
    protected open fun finishActSetOK() {
    }



    /**
     * 判定当前是否需要隐藏
     */
    protected open fun isShouldHideKeyBord(v: View?, ev: MotionEvent): Boolean {
        if (v != null && v is EditText) {
            val l = intArrayOf(0, 0)
            v.getLocationInWindow(l)
            val left = l[0]
            val top = l[1]
            val bottom = top + v.getHeight()
            val right = left + v.getWidth()
            return !(ev.x > left && ev.x < right && ev.y > top && ev.y < bottom)
        }
        return false
    }

    protected open fun finishCancel() {
    }


    /**
     * 隐藏软键盘
     */
    private fun hideSoftInput(token: IBinder?) {

    }

}




